using System;
using System.Windows.Media.Imaging;
using SalesPoint.Converters;
using SalesPoint.Security;
using Xtensive.Aspects;
using Xtensive.Orm;
using Xtensive.Orm.Security;

namespace SalesPoint.Model
{
  [TableMapping("Employees")]
  [HierarchyRoot]
  [Index("HireDate", "LastName", "Title")]
  public class Employee : GenericPrincipal
  {
    [Field, Key]
    public int Id { get; private set; }

    [Field(Length = 10)]
    public string LastName { get; set; }

    [Field(Length = 10, Indexed = true)]
    public string FirstName { get; set; }

    [Field(Length = 30, Indexed = true)]
    public string Title { get; set; }

    [Field(Length = 25)]
    public string TitleOfCourtesy { get; set; }

    [Field(Indexed = true)]
    public DateTime? BirthDate { get; set; }

    [Field]
    public DateTime? HireDate { get; set; }

    [Field(Length = 24)]
    public string HomePhone { get; set; }

    [Field(Length = 4)]
    public string Extension { get; set; }

    [Field(Length = Int32.MaxValue, LazyLoad = true)]
    public byte[] Photo { get; set; }

    [Infrastructure]
    public BitmapImage PhotoImage
    {
      get { return BitmapImageConverter.ConvertToBitmap(Photo); }
    }

    [Field]
    public string Notes { get; set; }

    [Field]
    public Employee ReportsTo { get; set; }

    [Field, Association(PairTo = "ReportsTo")]
    public EntitySet<Employee> ReportingEmployees { get; set; }

    [Field(Length = 255)]
    public string PhotoPath { get; set; }

    [Field, Association(PairTo = "Employee")]
    public EntitySet<Order> Orders { get; private set; }

    [Field]
    public EntitySet<Territory> Territories { get; private set; }

    [Field]
    public Address Address { get; set; }

    [Field(Length = 24)]
    public string Phone { get; set; }

    [Field(Length = 24)]
    public string Fax { get; set; }

    public Employee(Session session)
      : base(session)
    {
    }
  }
}